import request from '../utils/request';

export async function fetch(page = 1, pageSize = 1, filter = {}, sort) {
  return await request('/examQuestion', {
    params: {
      page,
      pageSize,
      filter: JSON.stringify(filter),
      sort: sort && JSON.stringify(sort),
    },
  });
}


export function doExam(param) {
  return request('/exam',
    {
      method: 'post',
      body: { ...param },
    },
  );
}

export function getTrains(phone, type, ref_type, ref_id) {
  return request('/exam',
    {
      params: {
        filter: JSON.stringify({ phone, type, ref_type, ref_id }),
      },
    },
  );
}

export function startExam(param) {
  return request('/exam',
    {
      method: 'post',
      body: { ...param },
    },
  );
}

export function endExam(param) {
  return request('/examEnd',
    {
      method: 'post',
      body: { ...param },
    },
  );
}

export function queryExamLibList(params) {
  if (params.filter)params.filter = JSON.stringify(params.filter);
  return request('/examLibList', {
    params,
  });
}

export function examEndCheck(params) {
  return request('/examEndCheck',
    {
      params,
    },
  );
}

export function fetchExamList(params) {
  return request('/examList',
    {
      params: {
        filter: JSON.stringify(params.filter),
      },
    },
  );
}

